<script>
	


export default {
	data(){
		return {

		};
	},
	onLaunch: function() {
		const _this=this;
		_this.driverLocationListener();
	},
	methods:{
		//司机实时位置监听
		driverLocationListener(){
			const _this=this;
			//uniapp自带方法
			uni.startLocationUpdate();
			uni.onLocationChange(function (res){
				const orderNo=uni.getStorageSync("orderNo");
				const workstatus = uni.getStorageSync("workStatus")
				const param={"latitude":res.latitude,"longitude":res.longitude}
				
				const location =[];
				location[0]={
					"latitude": "30.64110",
					"longitude": "104.04210",
					"orderNo": orderNo
				}
				
				location[1]={
					"latitude": "30.74110",
					"longitude": "104.06310",
					"orderNo": orderNo
				}
				location[2]={
					"latitude": "30.84110",
					"longitude": "104.08210",
					"orderNo": orderNo
				}
				location[3]={
					"latitude": "30.94110",
					"longitude": "104.10210",
					"orderNo": orderNo
				}
				location[4]={
					"latitude": "31.04110",
					"longitude": "104.11210",
					"orderNo": orderNo
				}
				//开始代驾时 循环实时坐标存入HBase
				if(workstatus== _this.Consts.WORK_STATUS.START_DRIVING){
					for(let index in location){
						_this.post("bigdata/driver/geo/cacheDriverLocation",location[index],(res)=>{
							const {success,message}=res.data
							if(!success){
								uni.showToast({
									icon: "error",
									title:"实时位置更新失败，可能会影响接单，请联系管理员！"
								})
							}
						})
					}
					
				}
				
				//司机不处在开始接单、结束代驾两种状态时，就把经纬度传到move司乘同显页面
				if(workstatus== _this.Consts.WORK_STATUS.RECEPTION_CUSTOMER
				||workstatus == _this.Consts.WORK_STATUS.ARRIVE_START_PLACE
				|| workstatus== _this.Consts.WORK_STATUS.START_DRIVING
				){
					_this.$emit("locationChange",param)
				}
				
				if(workstatus!= _this.Consts.WORK_STATUS.STOP_ACCPET_ORDER
				&& workstatus!= _this.Consts.WORK_STATUS.END_DRIVING
				){
					
					_this.post("driver/app/driver/SyncDriverPosition",param,(res)=>{
						console.log(res)
						const {success,data,message}=res.data
						if(!success){
							uni.showToast({
								icon:'error',
								title:'实时位置更新失败,可能会影响接单,请联系管理员'
							})
						}
					})
				}
				
			})
		
		
		}
	},
	onShow: function() {
		
	},
	onHide: function() {
	}
};
</script>

<style lang="scss">
@import 'uview-ui/index.scss';
</style>